﻿package test {
	import gear.core.Game;
	import gear.net.IMGLoader;
	import gear.net.LibData;

	import flash.display.Bitmap;
	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.utils.getTimer;

	/**
	 * @author admin
	 */
	public class TestLoader extends Game {
		override protected function startup() : void {
			var heads : Array = new Array();
			heads.push({key:"Kea", url:"http://94.100.119.243/1020950001-1021000000/1020977401-1020977500/1020977414_14_PM-F.jpeg"});
			heads.push({key:"Koosje", url:"http://94.100.115.147/616100001-616150000/616143701-616143800/616143765_14_Ww9p.jpeg"});
			heads.push({key:"Osiris", url:"http://94.100.121.34/1182400001-1182450000/1182431401-1182431500/1182431470_14_eJNT.jpeg"});
			heads.push({key:"Eniac", url:"http://94.100.116.70/1181500001-1181550000/1181546301-1181546400/1181546376_14_aadJ_1.jpeg"});
			heads.push({key:"Oscar", url:"http://94.100.120.180/1157200001-1157250000/1157247101-1157247200/1157247196_14_acnP_1.jpeg"});
			heads.push({key:"Leo", url:"http://94.100.114.38/1181500001-1181550000/1181545101-1181545200/1181545111_14_4mjb.jpeg"});
			heads.push({key:"Koen", url:"http://cache.hyves-static.net/images/bassie/bassie_2.jpg"});
			heads.push({key:"Lingyi", url:"http://94.100.121.150/1182400001-1182450000/1182428601-1182428700/1182428631_14_FqX7_1.jpeg"});
			heads.push({key:"Peter", url:"http://94.100.120.108/24150001-24200000/24167701-24167800/24167732_14_eqce.jpeg"});
			heads.push({key:"Jaap", url:"http://94.100.118.179/1176100001-1176150000/1176116801-1176116900/1176116866_14_t0ek.jpeg"});
			heads.push({key:"Linjia", url:"http://94.100.121.221/1181550001-1181600000/1181551601-1181551700/1181551612_14_Lv1Z_3.jpeg"});
			heads.push({key:"Guillaume", url:"http://94.100.120.73/1081550001-1081600000/1081570301-1081570400/1081570319_14_eQus_1.jpeg"});
			heads.push({key:"Zhao", url:"http://94.100.115.52/1181500001-1181550000/1181547901-1181548000/1181547913_14_XLWj.jpeg"});
			heads.push({key:"Robbert", url:"http://94.100.114.109/428550001-428600000/428550601-428550700/428550616_14_AxA-.jpeg"});
			heads.push({key:"Mister", url:"http://94.100.124.169/1155250001-1155300000/1155264301-1155264400/1155264347_14__OW4_2.jpeg"});
			heads.push({key:"KoenZelf", url:"http://94.100.118.216/1500001-1550000/1516601-1516700/1516607_14_qgpF.jpeg"});
			heads.push({key:"&#60;&#62;S&DR!", url:"http://94.100.114.139/996250001-996300000/996253401-996253500/996253468_14_lTgW_1.jpeg"});
			heads.push({key:"Hao", url:"http://cache.hyves-static.net/images/bassie/bassie_2.jpg"});
			heads.push({key:"Kim", url:"http://94.100.125.18/376650001-376700000/376653401-376653500/376653478_14_vqVu_1.jpeg"});
			heads.push({key:"Cat", url:"http://94.100.122.113/1181500001-1181550000/1181546901-1181547000/1181546938_14_HE8p_1.jpeg"});
			heads.push({key:"Laat", url:"http://cache.hyves-static.net/images/bassie/bassie_2.jpg"});
			heads.push({key:"Jan-Joost", url:"http://94.100.122.158/7400001-7450000/7400201-7400300/7400280_14_dtFf.jpeg"});
			heads.push({key:"&#24322;&#24418;", url:"http://94.100.122.10/1181500001-1181550000/1181548701-1181548800/1181548774_14_INSS_2.jpeg"});
			heads.push({key:"Kjj", url:"http://cache.hyves-static.net/images/bassie/bassie_2.jpg"});
			heads.push({key:"John", url:"http://cache.hyves-static.net/images/bassie/bassie_2.jpg"});
			heads.push({key:"Recky", url:"http://94.100.118.111/1181550001-1181600000/1181559901-1181560000/1181559925_14_0U2b.jpeg"});
			heads.push({key:"Linjia", url:"http://94.100.121.221/1181550001-1181600000/1181551601-1181551700/1181551612_14_Lv1Z_3.jpeg"});
			var i : int = 0;
			for each (var head:Object in heads) {
				var loader : IMGLoader = new IMGLoader(new LibData(head.url, head.key));
				loader.source = {index:i, start:getTimer()};
				loader.addEventListener(Event.COMPLETE, completeHandler);
				loader.addEventListener(ErrorEvent.ERROR, errorHandler);
				loader.load();
				i++;
			}
		}

		private function errorHandler(event : ErrorEvent) : void {
			var loader : IMGLoader = IMGLoader(event.currentTarget);
			trace(loader.source);
		}

		private function completeHandler(event : Event) : void {
			var loader : IMGLoader = IMGLoader(event.currentTarget);
			var bitmap : Bitmap = loader.getBitmap();
			var index : int = int(loader.source.index);
			bitmap.x = index % 10 * 80;
			bitmap.y = int(index / 10) * 80;
			trace(loader.key, getTimer() - loader.source.start);
			addChild(bitmap);
		}
	}
}
